import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class GameFlowControlPanel extends JPanel implements ActionListener {

	JButton place_planes_button;
	JButton undo_planes_button;
	JRadioButton set_plane_direction_up;
	JRadioButton set_plane_direction_right;
	JRadioButton set_plane_direction_down;
	JRadioButton set_plane_direction_left;
	ButtonGroup plane_direction_group;
	JLabel instruction_label;
	volatile boolean to_repaint_flow_control;
	volatile boolean plane_group_direction_changed;
	volatile boolean plane_button_pressed;
	volatile boolean plane_undo_button_pressed;
	public int plane_group_direction;
	

	public GameFlowControlPanel() {

		this.setLayout(new GridBagLayout());
		this.setPreferredSize(new Dimension(200, 200));

		this.to_repaint_flow_control = false;
		
		this.instruction_label = new JLabel();
		this.instruction_label.setText("Plane positioning is active! Right Click to deselect plane center!");
		GridBagConstraints c = new GridBagConstraints();
		c.gridx = 2;
		c.gridy = 3;
		
		this.place_planes_button = new JButton();
		this.place_planes_button.setText("Set Plane!");
		this.place_planes_button.addActionListener(this);
		this.place_planes_button.setVisible(true);
		
		this.undo_planes_button = new JButton();
		this.undo_planes_button.setText("Undo Plane Set!");
		this.undo_planes_button.addActionListener(this);
		this.undo_planes_button.setVisible(true);

		this.set_plane_direction_up = new JRadioButton("Up");
		this.set_plane_direction_up.setActionCommand("up_select");
		this.set_plane_direction_up.setVisible(true);
		this.set_plane_direction_up.addActionListener(this);
		this.set_plane_direction_up.setSelected(true);

		this.set_plane_direction_right = new JRadioButton("Right");
		this.set_plane_direction_right.setActionCommand("right_select");
		this.set_plane_direction_right.addActionListener(this);
		this.set_plane_direction_right.setSelected(true);

		this.set_plane_direction_down = new JRadioButton("Down");
		this.set_plane_direction_down.setActionCommand("down_select");
		this.set_plane_direction_down.setSelected(true);
		this.set_plane_direction_down.addActionListener(this);

		this.set_plane_direction_left = new JRadioButton("Left");
		this.set_plane_direction_left.setActionCommand("left_select");
		this.set_plane_direction_left.setSelected(true);
		this.set_plane_direction_left.addActionListener(this);

		this.plane_direction_group = new ButtonGroup();
		this.plane_direction_group.add(set_plane_direction_up);
		this.plane_direction_group.add(set_plane_direction_right);
		this.plane_direction_group.add(set_plane_direction_down);
		this.plane_direction_group.add(set_plane_direction_left);

		this.add(this.place_planes_button);
		this.add(this.undo_planes_button);
		this.add(this.set_plane_direction_up);
		this.add(this.set_plane_direction_right);
		this.add(this.set_plane_direction_down);
		this.add(this.set_plane_direction_left);
		this.add(this.instruction_label,c);
		
		this.plane_group_direction_changed = false;
		this.plane_button_pressed = false;
		this.plane_undo_button_pressed = false;

		System.out.println("FlowControl Created!");

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == this.place_planes_button){
		System.out.println("Planes Pressed!");
		this.plane_button_pressed = true;
		this.instruction_label.setText("Plane SET!");
		this.to_repaint_flow_control = true;
		this.instruction_label.setText("Plane positioning is active! Right Click to deselect plane center!");
		}
		if (e.getSource() == this.undo_planes_button){
			System.out.println("Undo PRESSED!");
			this.plane_undo_button_pressed = true;
		}
//		if (e.getSource().equals(this.set_plane_direction_down) || e.getSource() == this.set_plane_direction_right || e.getSource() == this.set_plane_direction_left || e.getSource() == this.set_plane_direction_up)
//		{
//			this.to_repaint_flow_control = true;
//		}
		if (e.getSource().equals(this.set_plane_direction_up)){
			this.plane_group_direction = 0;
			this.plane_group_direction_changed = true;
		}
		if (e.getSource().equals(this.set_plane_direction_right)){
			this.plane_group_direction = 1;
			this.plane_group_direction_changed = true;
		}
		if (e.getSource().equals(this.set_plane_direction_down)){
			this.plane_group_direction = 2;
			this.plane_group_direction_changed = true;
		}
		if (e.getSource().equals(this.set_plane_direction_left)){
			this.plane_group_direction = 3;
			this.plane_group_direction_changed = true;
		}
	}
}
